import Vue from 'vue'
import axios from 'axios'
// import vueViewload from 'vue-viewload';

import App from './App.vue'
import vueRouter from 'vue-router'
import routerConfig from './router.config';
import store from './store/'
import loading from './components/loading';

Vue.prototype.$http = axios;

// console.log(vueViewload)

require('./assets/css/base.css')//全局引入
Vue.use(loading)
Vue.use(vueRouter);
// 懒加载配置
// Vue.use(vueViewload, {
//   defaultPic: '../src/assets/images/loadingBefore.png',
//   errorPic: '../src/assets/images/loadingBefore.png',
//   threshold: -200,
//   effectFadeIn: true,
//   callback: function(ele, src) {
//   }
// })

//配置全局的cookis
axios.defaults.withCredentials = true;
//配置全局的baseURL
axios.defaults.baseURL = 'http://118.89.51.37:3000/';
// 添加全局的请求拦截器
axios.interceptors.request.use(function (config) {
  store.dispatch('showloading');
  return config;
}, function (error) {
  return Promise.reject(error);
});

// 添加全局的响应拦截器
axios.interceptors.response.use(function (response) {
  setTimeout(function () {
    store.dispatch('hideloading');
  }, 300);
  return response;
}, function (error) {
  return Promise.reject(error);
});

const router = new vueRouter(routerConfig)


new Vue({
  store,
  el: '#app',
  router,
  beforeCreate() {
    Vue.config.productionTip = false;
    Vue.config.devtools = false;
  },
  render: h => h(App)
})


